package com.yeming.socket.consumer

import java.io.{ObjectInputStream, ObjectOutputStream}
import java.net.Socket

import com.yeming.socket.`case`.LoggingData

import scala.util.Random

object Client {
  def main(args: Array[String]): Unit = {
    val socket = new Socket("127.0.0.1", 8888)

    val outputStream = new ObjectOutputStream(socket.getOutputStream)
    val inputStream = new ObjectInputStream(socket.getInputStream)
    //Wellid数组，之后通过Random随机取值。
    val wellIdArr: Array[String] = Array("10001", "10002", "10003", "10004")
    //wellName数组，之后可以通过Random随机取值
    val wellNameArr: Array[String] = Array("上三井_01", "上三井_02", "上三井_03", "上三井_04")
    //记录没一口井的当前记录深度，随机累加
    val wellDepthArr: Array[Double] = Array(0.0, 0.0, 0.0, 0.0)
    //一个随机数据生成类
    val rd = new Random()
    var i = 0L
    println(System.currentTimeMillis())
    while (i < 2000001) {
      val wellIndex: Int = rd.nextInt(4)
      outputStream.writeObject(LoggingData(i, "sockt_base_data", wellIdArr(wellIndex).toInt, wellNameArr(wellIndex),
        System.currentTimeMillis(), 0, wellDepthArr(wellIndex), rd.nextDouble() * 3, rd.nextDouble() * 15, null))
      val moreDepth: Double = rd.nextDouble() * 2
      wellDepthArr(wellIndex) += moreDepth
      i += 1
      outputStream.flush()
//      println(s"消息${i}发送成功！")
    }
    println("发送完成！")
    println(System.currentTimeMillis())

    outputStream.close()
    socket.close()
  }

}
